perm filename WEAVEC.TEX[WEB,ALS] blob sn#658523 filedate 1982-05-17 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\input webhdr
C00015 00003	\inx
C00017 00004	\fin
C00018 ENDMK
C⊗;
\input webhdr

\M1. Some of this code is optional for use when debugging only;
such material is enclosed between the delimiters  \&{debug}  and $  \&{gubed}
$.
Other parts, delimited by  \&{stat}  and $  \&{tats} $, are optionally included
if statistics about \.{WEAVE}'s memory usage are desired.

\Y\P\D \37$\\{debug}\S\B$\C{change this to `$\\{debug}\eqv\null$' when
debugging}\par
\P\D \37$\\{gubed}\S\T$\C{change this to `$\\{gubed}\eqv\null$' when
debugging}\par
\P\F \37$\\{debug}\S\\{begin}$\par
\P\F \37$\\{gubed}\S\\{end}$\Y\par
\P\D \37$\\{stat}\S$\C{change this to `$\\{stat}\eqv\.{@\}}$' when not
	gathering usage statistics}\par
\P\D \37$\\{tats}\S$\C{change this to `$\\{tats}\eqv\.{@\}}$' when not
	gathering usage statistics}\par
\P\F \37$\\{stat}\S\\{begin}$\par
\P\F \37$\\{tats}\S\\{end}$\par


\M2. Here now is the system-dependent part of the character set.
The code shown here is intended to be used on the Stanford {\sc SAIL} system,
and at other installations like CMU and ISI where essentially the same
extended character set is used. The fact that {\sc SAIL} has \.{\'\}\'} in the
wrong place turns out to cause no difficulty in this case.

\Y\P$\4\X2:\X\S$\6
\&{for} $\|i\K1\mathrel{\&{to}}\O37$ \1\&{do}\5
$\\{xchr}[\|i]\K\\{chr}(\|i)$;\2\6
$\\{xchr}[\\{left\_arrow}]\K\\{chr}(\O137)$;\5
$\\{xchr}[\\{not\_equal}]\K\\{chr}(\O33)$;\5
$\\{xchr}[\O33]\K\\{chr}(\O176)$;\par


\M3. The following code opens the input files. Since these files were listed
in the program header, we assume that the \PASCAL\ runtime system has
already checked that suitable file names have been given; therefore
no additional error checking needs to be done. We open the files
in a special mode that allows us to distinguish \\{form\_feed} from
\\{carriage\_return}. We will see below that \.{WEAVE} reads through the
entire input twice.

Local scuttlebutt says that nineteen buffers gives best results at {\mc SAIL}.

\Y\P\4\&{procedure}\1\  \37\\{open\_input};\C{prepare to read \\{web\_file} and
\\{change\_file}}\2\6
\&{begin} \37$\\{reset}(\\{web\_file},\39\.{\'\'},\39\.{\'/E/N:19\'})$;\5
$\\{reset}(\\{change\_file},\39\.{\'\'},\39\.{\'/E/N:19\'})$;\6
\&{end};\par


\M4. The following code opens \\{tex\_file}. Since this file was listed in the
program header, we assume that the \PASCAL\ runtime system has checked
that a suitable external file name has been given.

\Y\P$\4\X2:\X\mathrel{+}\S$\6
$\\{rewrite}(\\{tex\_file},\39\.{\'\'},\39\.{\'/N:19\'})$;\par


\M5. Input goes into an array called \\{buffer}.
We use a special feature of the local \PASCAL\ that
reads text into another array \\{aux\_buffer} first, thus saving
a bunch of procedure-call overhead.

\Y\P$\4\X2:\X\mathrel{+}\S$\6
\4\\{buffer}: \37\&{array} $[0\to\\{long\_buf\_size}]$ \1\&{of}\5
\\{ascii\_code};\2\6
\4\\{aux\_buffer}: \37\&{array} $[0\to\\{buf\_size}]$ \1\&{of}\5
\\{text\_char};\2\par

@ function input_ln(var f:text_file):boolean;
	{inputs a line or returns |false|}
label restart;
var n: integer; {the number of characters input by Hedrick's extended |read|}
@k:0..buf_size; {index into the buffers}
begin restart: if eof(f) then
	begin limit←0; input_ln←false;
	end
else	begin read(f,aux_buffer:n);
	if (line=1)∧(n=29)∧(aux_buffer[0]='C')∧(aux_buffer[8]=chr(@26)) then
		begin while (f↑≠chr(form_feed))∧(not eof(f)) do
			begin read_ln(f);
			read(f,aux_buffer:n); {skip file directory page}
			end;
		end;
	if n<buf_size then
		begin limit←n;
		if n>0 then for k←0 to limit-1 do buffer[k]←xord[aux_buffer[k]]
		else if f↑=chr(form_feed) then
			begin line←((line div @200000)+1)*@200000+1;
			read_ln(f); goto restart;
			end;
		end
	else	begin limit←buf_size-1;
		for k←0 to limit-1 do buffer[k]←xord[aux_buffer[k]];
		print_nl('! Input line too long'); error;
@Input line too long@
		while not eoln(f) do read(f,aux_buffer);
		end;
	read_ln(f); input_ln←true;
	end;
end;
@system dependencies@@changes for {\mc SAIL}@@
@Print error location based on input buffer@=
begin if changing then print('. (change file ')@else print('. (');
print_ln('p.',1+(line div @200000):0,',l.', line mod @200000:0, ')');
if loc≥limit then l←limit else l←loc;
for k←1 to l do
	if buffer[k-1]=tab_mark then print(' ')
	else print(xchr[buffer[k-1]]); {print the characters already read}
new_line;
for k←1 to l do print(' '); {space out the next line}
for k←l+1 to limit do print(xchr[buffer[k-1]]); {print the part not yet read}
if buffer[limit]="|" then print(xchr["|"]);
	{end of \PASCAL\ text in module names}
print(' '); {this space separates the message from future asterisks}
end
@system dependencies@@changes for {\mc SAIL}@@

\M6. When we wish to append the character $c$ to the output buffer, we write
`$\\{out}(c)$'; this will cause the buffer to be emptied if it was already
full. Similarly, `$\\{out2}(c↓1)(c↓2)$' appends a pair of characters.
A line break will occur at a space or after a single-nonletter
\TEX\ control sequence. The \\{write\_end\_of\_page} routine is used to
break the output into pages for ease in editing.

\Y\P\D \37$\\{oot}(\#)\S$\1\6
\&{if} $\\{out\_ptr}=\\{line\_length}$ \1\&{then}\5
\\{break\_out};\2\2\6
$\\{incr}(\\{out\_ptr})$;\5
$\\{out\_buf}[\\{out\_ptr}]\K\#$;\par
\P\D \37$\\{oot1}(\#)\S\\{oot}(\#)$\ \&{end} \par
\P\D \37$\\{oot2}(\#)\S\\{oot}(\#)\,\\{oot1}$\par
\P\D \37$\\{oot3}(\#)\S\\{oot}(\#)\,\\{oot2}$\par
\P\D \37$\\{oot4}(\#)\S\\{oot}(\#)\,\\{oot3}$\par
\P\D \37$\\{oot5}(\#)\S\\{oot}(\#)\,\\{oot4}$\par
\P\D \37$\\{out}\S$\ \&{begin} \37\\{oot1}\par
\P\D \37$\\{out2}\S$\ \&{begin} \37\\{oot2}\par
\P\D \37$\\{out3}\S$\ \&{begin} \37\\{oot3}\par
\P\D \37$\\{out4}\S$\ \&{begin} \37\\{oot4}\par
\P\D \37$\\{out5}\S$\ \&{begin} \37\\{oot5}\par
\Y\P\4\&{procedure}\1\  \37\\{write\_end\_of\_page};\2\6
\&{begin} \37\&{if} $\\{out\_ptr}>0$ \1\&{then}\5
$\\{flush\_buffer}(\\{out\_ptr})$;\2\6
$\\{write}(\\{tex\_file},\39\\{xchr}[\\{form\_feed}])$;\C{write a page mark}\6
$\\{out\_line}\K((\\{out\_line}\mathbin{\&{div}}\O200000)+1)\ast\O200000+1$;\6
\&{end};\par

@Print error message and prepare to write...@=
begin print_nl('! Line had to be broken (output p.',
@Line had to be broken@
1+(out_line div @200000):0,',l.',out_line mod @200000:0);
print_ln('):');
for k←1 to out_ptr do print(xchr[out_buf[k]]);
new_line; k←out_ptr; c←" ";
end
@system dependencies@@changes for {\mc SAIL}@@

\M7. \P$\X2:\X\mathrel{+}\S$\6
\&{debug} \37\&{if} $\\{tracing}=2$ \1\&{then}\6
\&{begin} \37$\\{print\_nl}(\.{\'Tracing\ after\ p.\'},\391+(\\{line}\mathbin{\&
{div}}\O200000):0,\39\.{\',l.\'},\39\\{line}\mathbin{\&{mod}}\O200000:0,\39\.{\'
:\'})$;\6
\&{if} $\\{loc}>50$ \1\&{then}\6
\&{begin} \37$\\{print}(\.{\'...\'})$;\6
\&{for} $\|k\K\\{loc}-50\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\6
\&{end}\6
\4\&{else} \&{for} $\|k\K1\mathrel{\&{to}}\\{loc}$ \1\&{do}\5
$\\{print}(\\{xchr}[\\{buffer}[\|k-1]])$;\2\2\6
\&{end}\2\6
\&{gubed}\par

@Output the code...@=
finish_line; flush_buffer(0); {insert a blank line, it looks nice}
if buffer[loc-1]≠"*" then out2("\")("M")
@\\M@
else	begin write_end_of_page;
	out2("\")("N");
@\\N@
	print('*',module_count:0); update_terminal; {print a progress report}
	end;
out_val(module_count); out2(".")(" ")
@system dependencies@@changes for {\mc SAIL}@@
@Phase III: Output the cross-reference index@=
print_nl('Writing the index...');
finish_line; write_end_of_page;
out4("\")("i")("n")("x"); finish_line;
@\\inx@
@Do the first pass of sorting@;
@Sort and output the index@;
write_end_of_page;
out4("\")("f")("i")("n"); finish_line;
@\\fin@
@Output all the module names@;
out4("\")("c")("o")("n"); finish_line;
@\\con@
print('Done.');
@system dependencies@@changes for {\mc SAIL}@@

\inx
\+\\{ascii\_code}, 5.
\+\\{aux\_buffer}, \[5].
\+\&{begin}, 1.
\+\\{break\_out}, 6.
\+\\{buf\_size}, 5.
\+\\{buffer}, \[5], 7.
\+\\{carriage\_return}, 3.
\+\\{change\_file}, 3.
\+{changes for {\mc SAIL}}, 1, 2, 3, 4, 5, 6, 7.
\+\\{chr}, 2.
\+\&{debug}, \[1].
\+\&{end}, 1.
\+\\{flush\_buffer}, 6.
\+\\{form\_feed}, 3, 6.
\+\&{gubed}, \[1].
\+\\{incr}, 6.
\+\\{left\_arrow}, 2.
\+\\{line}, 7.
\+\\{line\_length}, 6.
\+\\{loc}, 7.
\+\\{long\_buf\_size}, 5.
\+\\{not\_equal}, 2.
\+\\{oot}, \[6].
\+\\{oot1}, \[6].
\+\\{oot2}, \[6].
\+\\{oot3}, \[6].
\+\\{oot4}, \[6].
\+\\{oot5}, \[6].
\+\\{open\_input}, \[3].
\+\\{out}, \[6].
\+\\{out\_buf}, 6.
\+\\{out\_line}, 6.
\+\\{out\_ptr}, 6.
\+\\{out2}, \[6].
\+\\{out3}, \[6].
\+\\{out4}, \[6].
\+\\{out5}, \[6].
\+\\{print}, 7.
\+\\{print\_nl}, 7.
\+\\{reset}, 3.
\+\\{rewrite}, 4.
\+\&{stat}, \[1].
\+{system dependencies}, 1, 2, 3, 4, 5, 6, 7.
\+\&{tats}, \[1].
\+\\{tex\_file}, 4, 6.
\+\\{text\_char}, 5.
\+\\{tracing}, 7.
\+\\{web\_file}, 3.
\+\\{write}, 6.
\+\\{write\_end\_of\_page}, \[6].
\+\\{xchr}, 2, 6, 7.
\fin
\con